package com.itheima.day09;

import java.util.ArrayList;
import java.util.Scanner;

public class TestClassCase05 {

    public static void main(String[] args) {


        //创建集合
        ArrayList<Student> list=new ArrayList<>();

        Student s1=getStu();
        Student s2=getStu();
        Student s3=getStu();

        list.add(s1);
        list.add(s2);
        list.add(s3);

        for (int i = 0; i < list.size(); i++) {
            Student s=list.get(i);
            System.out.println("姓名："+s.getName()+",年龄："+s.getAge());

        }

    }

    private static Student getStu() {


        Student s=new Student();


        Scanner sc=new Scanner(System.in);

        System.out.println("请输入姓名:");
        String name=sc.next();

        System.out.println("请输入年龄:");
        int age=sc.nextInt();

        s.setName(name);
        s.setAge(age);

        return s;
    }
}
